package cn.lili.modules.union.mapper;

import cn.lili.modules.member.entity.dos.UnionMember;
import cn.lili.modules.member.entity.dto.NumberOfOwnerDTO;
import cn.lili.modules.member.entity.vo.MemberEvaluationListVO;
import cn.lili.modules.order.order.entity.dos.Order;
import cn.lili.modules.order.order.entity.dos.OrderFlow;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

public interface UnionMemberMapper extends BaseMapper<UnionMember> {

    /**
     * 分页查询工会成员
     * @param page
     * @param queryWrapper
     * @return
     */
    /*@Select("SELECT IFNULL((select SUM(flow_price) from lilishop_order.li_order_flow lof " +
            "where lum.member_id = lof.lower_commiss_id " +
            "and DATE_FORMAT(lof.create_time, '%Y%m' ) = DATE_FORMAT(CURDATE() , '%Y%m') " +
            "and lof.profit_sharing = 'FINISHED'), 0) as monthMoney, " +
            "MAX(lum.member_id) as memberId, " +
            "MAX(lum.member_name) as memberName, " +
            "MAX(lum.join_time) as joinTime, " +
            "MAX(lum.create_time) as createTime, " +
            "MAX(lum.`status`) as status " +
            "FROM lilishop_user.li_union_member_apply lum " +
            "${ew.customSqlSegment}")*/
    Page<UnionMember> getByPage (Page page, @Param("um") UnionMember unionMemberParams);

    /**
     * 查询成员上月业绩
     * @param memberId
     * @return
     */
    @Select("SELECT SUM(lof.flow_price) as lastMonthMoney " +
            "FROM lilishop_user.li_union_member lum " +
            "LEFT JOIN lilishop_order.li_order_flow lof on lum.member_id = lof.lower_commiss_id " +
            "WHERE DATE_FORMAT(lof.create_time, '%Y%m' ) = DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 MONTH), '%Y%m') " +
            "and lum.member_id = ${memberId} ")
    Double getLastMonthMoneyByMemberId (@Param("memberId") String memberId);

    Page<Order> getCurrentMonthByMember (@Param(Constants.WRAPPER) Wrapper<Order> queryWrapper);




    @Select("SELECT union_id,member_id from li_union_member where member_id=#{memberId} limit 1")
    UnionMember getOneById (@Param("memberId") String memberId);

    /**
     * 查询工会下的店主业绩
     */
    BigDecimal selectOrderTotalPrice(NumberOfOwnerDTO dto);
}
